﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GcmpModelInterface.h"
#include "IObject.h"

namespace gcmp
{
    class IDocument;
    class ICategory;
    class IElement;
    class UniIdentity;
    class IUidTree;

    /// \brief 类别库
    /// 
    /// ICategoryLibrary文档唯一，负责管理文档中的所有类别
    class GCMP_MODEL_INTERFACE_EXPORT ICategoryLibrary : public IObject
    {
        DEFINE_CAST_DERIVED(gcmp::ICategoryLibrary, gcmp::IObject);
    public:
        /// \brief 获得类别库
        /// \param pDocument 文档
        /// \return 类别库指针
        static ICategoryLibrary* Get(IDocument* pDocument);

        /// \brief 得到Category分层树对象
        /// \return Category分层树对象
        virtual const IUidTree* GetCategoryUidTree() const = 0;

        /// \brief 得到Category分层树对象
        /// \return Category分层树对象
        virtual IUidTree* GetCategoryUidTree() = 0;

        /// \brief 根据Uid获取类别
        /// 
        /// 非内建类别，可通过此接口获得
        /// \param categoryUid 类别Uid
        /// \return const ICategory* 类别指针
        virtual const ICategory* GetCategory(const UniIdentity& categoryUid) const = 0;

        /// \brief 获得类别库中所有的类别
        /// 
        /// 包括内建类别和非内建类别
        /// \return 类别库中所有的类别
        virtual std::vector<const ICategory*> GetAllCategories() const = 0;

        /// \brief 添加类别
        /// 
        /// 若该Category已存在于CategoryLibrary中，则添加失败；若所添加的Category存在parentCategory，但是parentCategory未加入
        /// CategoryLibrary中，则添加失败
        /// \param category 需要添加到类别库中的类别
        /// \return true-添加成功；false-添加失败
        virtual bool AddCategory(OwnerPtr<ICategory> category) = 0;

        /// \brief 删除类别
        /// CategoryLibrary中未找到此Category，则删除失败；若删除的Category存在子Category，会一起被删除
        /// \param categoryUid 类别Uid
        /// \return true-删除成功；false-删除失败
        virtual bool DeleteCategory(const UniIdentity& categoryUid) = 0;

        /// \brief 更新类别，能实现Category名称、描述的永久更改
        ///
        /// \param pNewCategory 包含新信息的新类别
        /// \return true: 更新成功，false: 更新失败
        virtual bool UpdateCategory(const ICategory* pNewCategory) = 0;
    };
}



